package com.douwong.student.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.douwong.student.R;
import com.douwong.student.interfaces.ItemListener;


/**
 * @autor yichao
 * @time 2016/11/219:55
 * @des ${TODO}
 */
@SuppressWarnings("ResourceType")
public class PersonInfoItemView extends RelativeLayout {

    private TextView mViewName;
    private ImageView mImageEnter;
    private TextView mViewTitle;
    public PersonInfoItemView(Context context) {
        this(context,null);
    }

    public PersonInfoItemView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public PersonInfoItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }



    private void init(Context context, AttributeSet attrs) {

        View view = LayoutInflater.from(context).inflate(R.layout.personifno_item,this,true);

        mViewTitle = (TextView) view.findViewById(R.id.nickname_text);
        mViewName = (TextView) view.findViewById(R.id.nick_name);
        mImageEnter = (ImageView) view.findViewById(R.id.imag_enter);


        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PersonInfoItem);
        String viewTitle = a.getString(0);
        String viewName = a.getString(1);
        int resourceId = a.getResourceId(2,R.mipmap.enter);

        if (viewTitle != null) {
            mViewTitle.setText(viewTitle);
        }

        if (viewName != null) {

            mViewName.setText(viewName);
        }
        if (resourceId!=0){
            mImageEnter.setImageResource(resourceId);
        }
        a.recycle();
        mImageEnter.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mItemListener!=null){
                    mItemListener.onImagClick(v);

                }
            }
        });

    }



    /**
     * 设置内容
     * @param charSequence
     */
    public void setViewName(CharSequence charSequence){
        mViewName.setText(charSequence);
    }

    /**
     * 设置图片是否可见
     * @param viesible
     */
    public void setImageViesible(int viesible){
        mImageEnter.setVisibility(viesible);
    }

    /**
     * 设置图片
     * @param resoure
     */
    public void  setImageResoure(int resoure){
        mImageEnter.setImageResource(resoure);
    }
    private ItemListener mItemListener;
    public void setImagListener(ItemListener imagListener){
        this.mItemListener=imagListener;
    }

    /**
     * 设置标题颜色
     * @param color
     */
    public void setViewTitleColor(int color){

        mViewTitle.setTextColor(color);
    }
}
